/**
 * @file app_main.c
 * @brief 
 * @author yejing (yejh@gongniu.cn)
 * @version 1.0
 * @date 2024-05-15
 * 
 * Copyright 2024-2025 GongNiu Inc. All Rights Reserved.
 * 
 */

#include <stdio.h>

#include "bull_hal_sys_thread.h"
#include "bull_hal_sys_timer.h"
#include "bull_hal_sys_system.h"

#include "esp_log.h"

static const char* SYS_TAG = "sys_timer";

TIMER_HANDLE Bull_sys_time_handle = NULL;

//用于检查蓝牙设备是否ready
#define TEST_TIMER_READY_TIME  1*1000


static void bull_timer_ready_timer_cb(TIMER_HANDLE xTimer)
{   
    static int call_num = 0;

    ESP_LOGI( SYS_TAG, "app_init_thread bull_timer_ready_timer_cb:%d", call_num++ );
}


static void bull_sys_timer_creat_test( void )
{

    Bull_sys_time_handle = bull_hal_sys_timer_create( "bull_sys_timer_test", TEST_TIMER_READY_TIME, true, (void *)0, bull_timer_ready_timer_cb );
   
    bull_hal_sys_timer_start( Bull_sys_time_handle, 0 );
}

/**
 * @brief 
 * 
 * @param param 
 */
static void app_init_thread(void* param)
{
    bull_sys_timer_creat_test();
    
    while ( 1 ){
        ESP_LOGI( SYS_TAG, "free heap size:%ld\n", bull_hal_sys_get_free_heap_size() );
        bull_hal_sys_sleep( 500 );
    }
}



/**
 * @brief 
 * 
 */
static void app_init_entry(void)
{


    bull_hal_sys_thread_create( app_init_thread,
    "app_init_thread",
    4*4096 ,
    NULL,
    10,
    NULL);

}

/**
 * @brief 
 * 
 */
void app_main(void)
{

    app_init_entry();
}
